package com.polaris.live.common.photo.image_preview

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.bumptech.glide.Glide
import com.polaris.live.common.R

/**
 * 预览的viewpage
 *
 * @author Created by 半仙 on 2023/8/15/015 14:12
 */
class ImageVpAdapter(private val activity: Activity, private val imageInfo: List<String>) :
        PagerAdapter() {

    override fun getCount(): Int = imageInfo.size

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        //这里可以区分视频和图片
        val converView = View.inflate(activity, R.layout.adapter_big_img, null)
        val bigImg = converView.findViewById<ImageView>(R.id.item_big_img)
        Glide.with(bigImg.context).load(imageInfo[position]).into(bigImg)

        container.addView(converView)


        return converView
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun isViewFromObject(view: View, obj: Any): Boolean = view === obj
}